#!/bin/bash

# 测试DataServer解析功能的脚本
# 用于验证ZooKeeper中旧格式数据的解析是否正常

echo "=== 测试DataServer解析功能 ==="

METASERVER_URL="http://localhost:8300"

echo "1. 检查系统健康状态..."
curl -s "${METASERVER_URL}/api/v1/admin/health" | jq .

echo -e "\n2. 获取当前DataServer状态..."
curl -s "${METASERVER_URL}/api/v1/admin/dataservers" | jq .

echo -e "\n3. 刷新DataServer缓存..."
curl -s -X POST "${METASERVER_URL}/api/v1/admin/refresh-dataservers" | jq .

echo -e "\n4. 清理ZooKeeper无效数据..."
curl -s -X POST "${METASERVER_URL}/api/v1/admin/cleanup-zk" | jq .

echo -e "\n5. 再次检查DataServer状态..."
curl -s "${METASERVER_URL}/api/v1/admin/dataservers" | jq .

echo -e "\n6. 测试allocateBlocks功能..."
curl -s -X POST "${METASERVER_URL}/api/v1/meta/allocateBlocks" \
  -H "Content-Type: application/json" \
  -d '{
    "fileId": "test-file-123",
    "bytes": 1024
  }' | jq .

echo -e "\n=== 测试完成 ==="
